package com.baixun.gassystem.service.impl;

import com.baixun.gascommon.utils.RedisUtils;
import com.baixun.gasentity.entity.SysDataPermission;
import com.baixun.gasentity.entity.SysVideoMessage;
import com.baixun.gassystem.mapper.SysDataPermissionMapper;
import com.baixun.gassystem.mapper.SysDepartmentUserMapper;
import com.baixun.gassystem.mapper.SysVideoMessageMapper;
import com.baixun.gassystem.service.SysDataPermissionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @program: 上海燃气驾驶舱
 * @description:数据权限实现类
 * @description:数据权限实现类
 * @author: yesong
 **/
public class SysDataPermissionServiceImpl extends ServiceImpl<SysDataPermissionMapper, SysDataPermission> implements SysDataPermissionService {

    @Autowired
    private SysVideoMessageMapper videoMessageMapper;

    @Autowired
    private SysDataPermissionMapper dataPermissionMapper;

    @Autowired
    private SysDepartmentUserMapper departmentUserMapper;

    @Autowired
    private RedisUtils redisUtils;


    /**
     * 获取用户的权限树结构
     *
     * @param userId       用户ID
     * @param departmentId 部门ID
     * @return 用户的权限树
     */

    @Override
    // 查询所有的列表（权限树结构）
    public List<SysDataPermission> getAllPermissions(Long userId, Long departmentId) {
        return dataPermissionMapper.selectAllPermissions(userId, departmentId);
    }


    // 更新权限（批量增补或取消权限）
    @Transactional
    @Override
    public void updatePermissions(Long userId, Long departmentId,
                                  List<Long> nodesToAdd, List<Long> nodesToRemove) {
        dataPermissionMapper.batchUpdatePermissions(userId, departmentId, nodesToAdd, nodesToRemove);
    }

    /**
     * 构建树形结构
     * @param nodes 所有节点
     * @return 树形结构的节点列表
     */



}
